﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;


namespace Pong_Project.Game_objects
{
    /// <summary>
    /// An obstacle that will deflect the ball when hit. Spawns in the center area
    /// of the screen, must not interfere with the powerups. 
    /// Obstacles will be  instansiated at startup, and remain put for the whole game. 
    /// 
    /// Improvement suggestions: Include obstacles that may disappear and then reappear like the powerups. This can also be achieved by setting obstacle color to the background color of the board.
    /// </summary>
    class Obstacle : GameObject
    {
        private Ball ball;
        private bool visible;

        public Obstacle(GameObjectIdentity identity, Vector2 position, Ball ball)
            : base(identity, position)
        {
            this.ball = ball;
            visible = true;
            LayerDepth = 0.0f;
        }

        int edgePixels = 8;

        public Rectangle EdgeTop
        {
            get { return new Rectangle((int)PositionX, (int)PositionY, (int)Width, edgePixels); }
        }

        public Rectangle EdgeBot
        {
            get { return new Rectangle((int)PositionX, (int)(Bottom - edgePixels), (int)Width, edgePixels); }
        }

        public Rectangle EdgeLeft
        {
            get { return new Rectangle((int)PositionX, (int)PositionY, edgePixels, (int)Height); }
        }

        public Rectangle EdgeRight
        {
            get { return new Rectangle((int)(Right - edgePixels), (int)PositionY, edgePixels, (int)Height); }
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            // When the obstacle shall reappear, it must not intersect with ball
            if (!Intersects(ball))
            {
                visible = true;
            }

            base.Update(gameTime);
        }

        public override void Reset()
        {
            // If the the obstacle has disappeared, reset must make it reappear
            visible = true;
            Rotation = 0.0f;
            LayerDepth = 0.0f;
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (visible)
            {
                base.Draw(spriteBatch);
            }
        }
    }
}
